package com.thti.mecool.client.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.threeti.mecool.mobile.interfaces.dto.SalesPromoterDto;
import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.widget.Toolbar;

public class ShowSalersActivity extends BaseActivity {
	ListView listView;
	List<SalesPromoterDto> salesPromoters;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		noTitle();
		setContentView(R.layout.mecool_show_salers);
		initToolbar();
		getData();
		init();
		service();
		
	}
	
	private void getData(){
		salesPromoters=new ArrayList<SalesPromoterDto>();
		for(int i=0;i<6;i++){
			SalesPromoterDto salesPromoterDto=new SalesPromoterDto();
			salesPromoterDto.setName("销售员"+(i+1));
			salesPromoterDto.setIdCardNo(String.valueOf(i));
			salesPromoters.add(salesPromoterDto);
		}
		
	}
	
	private void init(){
		listView=(ListView)findViewById(R.id.mecool_show_salers_listview);
		
	}

	public void initToolbar(){
		Toolbar toolbar=new Toolbar(this);
		toolbar.setToolbarCentreText("销售员列表");
		Toolbar.left_btn.setOnClickListener(leftbuttonListener);
		Toolbar.hideRightButton();
		Toolbar.left_btn.setImageResource(R.drawable.mecool_go_back);
	}
	
	private OnClickListener leftbuttonListener=new ImageButton.OnClickListener(){

		@Override
		public void onClick(View v) {
			finish();
	}};
	
	private void service(){
		listView.setAdapter(SalersAdapter);
		listView.setOnItemClickListener(itemClickListener);
	}
	
	OnItemClickListener itemClickListener=new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent=new Intent(ShowSalersActivity.this,SalersRateActivity.class);
			intent.putExtra("id", salesPromoters.get(arg2).getIdCardNo());
			startActivity(intent);
		}
	};
	
	private BaseAdapter SalersAdapter = new BaseAdapter() {
		LinearLayout layout;
		TextView tv;
		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			layout=new LinearLayout(ShowSalersActivity.this);
			layout.setPadding(10, 0, 10, 0);
			layout.setBackgroundResource(R.drawable.mecool_listview_selector);
			layout.setGravity(Gravity.CENTER_VERTICAL);
			tv=new TextView(ShowSalersActivity.this);
			tv.setTextColor(Color.BLACK);
			tv.setText(salesPromoters.get(arg0).getName());
			layout.addView(tv);
			return layout;
		}
		
		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}
		
		@Override
		public Object getItem(int arg0) {
			return salesPromoters.get(arg0);
		}
		
		@Override
		public int getCount() {
			return salesPromoters.size();
		}
	};	
}
